package com.leen.common.util;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

/**
 * 日期工具类说明
 *
 * @author admin
 * @date 2021-05-25
 */
public class DateTimeUtil {


    /**
     * 在日期上面追加为23:59:59
     * @param startDate
     * @return
     */
    public static Date dateToEnd(Date startDate){
       //日期转换为 jdk8 LocaDate
        LocalDateTime localDateTime = LocalDateTime.ofInstant(startDate.toInstant(), ZoneId.systemDefault());
        localDateTime=localDateTime.plusHours(23L).plusMinutes(59L).plusSeconds(59L);


        // localDateTime转换为 Date
        ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.systemDefault());
        return Date.from(zonedDateTime.toInstant());
    }

    /**
     * 在日期上面追加天数
     * @param startDate
     * @param day
     * @return
     */
    public static Date dateToDay(Date startDate,long day){
        //日期转换为 jdk8 LocaDate
        LocalDateTime localDateTime = LocalDateTime.ofInstant(startDate.toInstant(), ZoneId.systemDefault());
        localDateTime =localDateTime.plusDays(day);

        // localDateTime转换为 Date
        ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.systemDefault());
        return Date.from(zonedDateTime.toInstant());
    }


}
